<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Hash;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class CollectController extends Controller
{
    public function getGeren()
        {
        $did = DB::table('gonggao')->get();
        $dif = DB::table('link')->get();
        return view('geren.geren',['aaa'=>$did],['lianjie'=>$dif]);
        }

        

    public function getSc(Request $request)
    {
    	// dd(222);
    	//接收id
        $id = $request->input('id');
        //查询数据库
        $res = DB::table('goods')->where('id',$id)->first();
        $data['price'] = $res->price;
        $data['proname'] = $res->proname;
        $data['img'] = $res->image;
       // $proname = $res->proname;
       // $image = $res->image;
        // dd($price);
        // dd($res);
        $data['userid'] = session('id');
        if(!session('id')){
            return view('logs.logins');
        }else{
        // $data['proname'] = $res->'proname';
        // $data['img'] = $res['image'];
        // $data['price'] = $res->'price';
        // $data = $res->only(['proname','image','price']);
        // $data=$res->only['price','proname'];

        // dd($res);
        //判断
        // dd(22); 

        //dd($data);
       // $der = DB::table('collect')->insert(['$price'],['$proname'],['$image'],['$data']);
        $der = DB::table('collect')->insert($data);

        return view('geren.success');
        // dd($der);n

 //        if(!$user->id == $request->input('id')){
    		
 //    		return back();
 //    	}else{
 //            //修改后台商品状态
 //             $res = DB::table('goods')->where('id',$id)->update(['state'=>4]);
		}
	}
		//将数据库中数据遍历出来
    	public function getCollect()
    	{
		    $dis = DB::table('collect')->get();
		     
            // dd($der);
            $did = DB::table('gonggao')->get();
            $dif = DB::table('link')->get();
            return view('geren.collect',['bian'=>$dis,'aaa'=>$did,'lianjie'=>$dif]);
      
    	}

    	public function delCollect(Request $request)
    	{
    		$id = $request->input('id');
    		$soso = DB::table('collect')->where('id',$id)->count();

    		$dell = DB::table('collect')->where('id',$id)->delete();
    	if($dell){
    		//成功 重定向 页面跳转到列表页
    		return redirect('/collect')->with('success','数据删除成功');
    	}else{
    		//失败 回到添加页
    		return back()->with('error','数据删除失败');
    	}

    	}
        
        
}
